home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MACSHELL / MS1 / SHELL_SO / PRINTCMD.C < prev    next >
Text File  |  1992-12-02  |  7KB  |  284 lines

  1. /*
  2.  *    MacShell Source File
  3.  *
  4.  *    Copyright (c) 1989, 1990, 1991, 1992  Suick Bay Technologies.  All rights reserved.
  5.  *
  6.  *
  7.  *    RESTRICTIONS ON MacShell program and source code.
  8.  *
  9.  *    Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
  10.  *    restricted use by the owner of the CDROM "Disk to the future II".
  11.  *
  12.  *    Ñ╩No permission is granted for any commercial use without the written
  13.  *    consent of the Suick Bay Technologies.
  14.  *
  15.  *    Ñ╩No permission is granted for any redistribution of any kind use without
  16.  *    the written consent of the Suick Bay Technologies.
  17.  *
  18.  *    Ñ╩Permission is granted to use this for any personal noncommercial use.
  19.  *
  20.  *    Ñ╩You may not distribute source or executable code at all, nor may you 
  21.  *    distribute it with or within a commercial product without the written
  22.  *    consent of the Suick Bay Technologies.  Please send modifications to 
  23.  *    the author for inclusion in updates to the program.  Thanks.
  24.  *
  25.  *
  26.  *    MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  27.  *    WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  28.  *    PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  29.  *
  30.  *    SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  31.  *    INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
  32.  *    OR ANY PART THEREOF. 
  33.  *
  34.  *    In no event will Suick Bay Technologies be liable for any lost revenue
  35.  *    or profits or other special, indirect and consequential damages, even if
  36.  *    Suick Bay Technologies has been advised of the possibility of such damages.
  37.  *
  38.  *    Suick Bay Technologies can be reached at:
  39.  *    
  40.  *    8768 Cottonwood lane
  41.  *    Maple Grove, MN 55369
  42.  *    Voice: (612) 425-7025
  43.  *    AppleLink: D5233
  44.  *    
  45.  *
  46.  *    No parts of this software may be reproduced or stored in a
  47.  *    retrieval system or transmitted in any form, or any means,
  48.  *    electronic, mechanical, photocopying, recording or otherwise,
  49.  *    without the prior written permission of Suick Bay Technologies.
  50.  *    
  51.  *    Spread the word and not the disk.
  52.  *    
  53.  *    SPK 012290    :    Initial
  54.  */
  55.  
  56. #include     <PrintMgr.h>
  57.  
  58. #define        PrintDialogID        917
  59. #define        PageSetUpDialogID    918
  60.  
  61. #include    "SystemPub.h"
  62. #include    "Proc.h"
  63. #include    "Shell.h"
  64. #include    "Path.h"
  65.  
  66. #define        BUFSIZE        256
  67.  
  68. /*******************************************************************
  69.  *
  70.  *    Function Pr
  71.  *
  72.  *    PathName Callback function
  73.  *
  74.  *    usage pr [options] files
  75.  *
  76.  *******************************************************************/
  77.  
  78. int16        prCols = 1,
  79.             portrait = TRUE,
  80.             prHeader = TRUE,
  81.             prJob     = FALSE,
  82.             prSetup = FALSE;
  83.             
  84. extern        WordBreak(),
  85.             AutoScroll();
  86.  
  87. extern        THPrint     hPrint;
  88. extern        TPPrPort     pPrPort;
  89. extern        Boolean     aborted;
  90.  
  91. void        PrCallBack( WHandle ShellWh, int16 ProcID, char *path, char *last,
  92.                         pathType what, int16 vRefNum, int32 dirID )
  93. {
  94. CInfoPBRec         pb;
  95. char            str[ 256 ];
  96. PEHandle         hPE = NULL;
  97. Rect            viewRect;
  98. int16             copies;
  99. TPrStatus         prStatus;
  100. DialogPtr         dPtr;
  101. int32            grow, max;
  102.  
  103.     max = MaxMem( &grow );
  104.  
  105.     strcpy( str, last );
  106.     CtoPstr( str );
  107.     
  108.     pb.hFileInfo.ioCompletion     = NULL;
  109.     pb.hFileInfo.ioNamePtr         = (StringPtr) str;
  110.     pb.hFileInfo.ioVRefNum         = vRefNum;
  111.     pb.hFileInfo.ioDirID         = dirID;
  112.     pb.hFileInfo.ioFDirIndex     = 0;
  113.     
  114.     PBHGetFInfo( &pb, FALSE );
  115.         
  116.     if( pb.hFileInfo.ioFlFndrInfo.fdType == 'TEXT'  )
  117.         {
  118.         if( OpenPrinter() && (aborted == FALSE) )
  119.             {
  120.             if( prJob && !PrJobDialog( hPrint ) )
  121.                 {
  122.                 ClosePrinter();
  123.                 return;
  124.                 }
  125.  
  126.             procPrintf( ShellWh, ProcID, "    %ps\n", str );
  127.             hPE = PENew( &viewRect );
  128.  
  129.             copies = (**hPrint).prJob.iCopies;
  130.             if ((**hPrint).prJob.bJDocLoop == bSpoolLoop)
  131.                 copies = 1;
  132.         
  133.             dPtr = GetNewDialog( PrintDialogID, NULL, -1L );
  134.             CenterDialog( dPtr );
  135.             DrawDialog( dPtr );
  136.         
  137.             CursorWait();
  138.             aborted = FALSE;
  139.  
  140.             SetRect( &viewRect, 0, 0, 10, 10 );
  141.             
  142.             if( hPE )
  143.                 {
  144.                 (**hPE).txFont = monaco; /* chicago */
  145.                 (**hPE).txSize = fontSize;
  146.                 (**hPE).txFace = 0;
  147.             
  148.                 (**hPE).viewOrgH = -5;
  149.                 (**hPE).wordBreak = ( ProcPtr ) WordBreak;
  150.                 (**hPE).clikLoop = ( ProcPtr ) AutoScroll;
  151.                 
  152.                 pPrPort = PrOpenDoc( hPrint, NULL, NULL );
  153.                 
  154.                 if( pPrPort )
  155.                     {
  156.                     if( ReadFile( vRefNum, dirID, str, hPE ) )
  157.                         {
  158.                         for( ; copies--; )
  159.                             {
  160.                             if( AbortPrint() )
  161.                                 break;
  162.                                 
  163.                             if( PrintEditWindow( hPE, str,
  164.                                 NULL, prCols, prHeader ) == FALSE )
  165.                                 break;
  166.                             }
  167.                         }
  168.                         
  169.                     PrCloseDoc( pPrPort );
  170.                     }
  171.                     
  172.                 PEDispose( hPE );
  173.                 }
  174.                 
  175.             if( !AbortPrint() )
  176.                 if( (**hPrint).prJob.bJDocLoop == bSpoolLoop )
  177.                     PrPicFile( hPrint, nil, nil, nil, &prStatus );
  178.         
  179.             DisposDialog( dPtr );
  180.             InitCursor();
  181.             ClosePrinter();
  182.             }
  183.         }
  184. }
  185.  
  186. /*******************************************************************/
  187.  
  188. void        PrFiles( WHandle ShellWh, int16 ProcID, char *argument )
  189. {
  190. ShellWindRec    **MyShell;
  191.  
  192.     MyShell = (ShellWindRec **) (**ShellWh).thing;
  193.  
  194.     ExpandPath( ShellWh, ProcID, argument, (ProcPtr) PrCallBack,
  195.             (**MyShell).pwdVRefNum, (**MyShell).pwdDirID );
  196.  
  197.     ResetShellPWD( ShellWh );
  198. }
  199.  
  200. /*******************************************************************/
  201.  
  202. Boolean            DoPR( int16 ProcToken, WHandle ShellWh, int16 ProcID, char *string )
  203. {
  204. int16                i, argc;
  205. char            *cp, argument[ 256 ];
  206. ShellWindRec    **MyShell = (ShellWindRec **) (**ShellWh).thing;
  207.  
  208.     switch( ProcToken )
  209.         {
  210.         case    PROC_INIT    :
  211.             (**MyShell).Proc[ ProcID ].flags = TRUE;
  212.             break;
  213.             
  214.         case    PROC_TERM    :
  215.         case    PROC_BREAK    :
  216.             /* Tell the shell that we're done */
  217.             SendOutToken( ShellWh, ProcID, PROC_BREAK );
  218.             /* Turn ourself off */
  219.             (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  220.             break;
  221.             
  222.         case    PROC_STDIN    :
  223.             if( (**MyShell).Proc[ ProcID ].flags )
  224.                 {
  225.                 (**MyShell).Proc[ ProcID ].flags = FALSE;        
  226.  
  227.                 aborted = FALSE;
  228.                 prCols = 1;
  229.                 
  230.                 /* get arguments */
  231.                 argc = (**MyShell).Proc[ ProcID ].argc;
  232.                 for( i = 1; i < argc; i++ )
  233.                     {
  234.                     GetArgv( ShellWh, ProcID, i, argument );
  235.                     cp = argument;
  236.         
  237.                     if( *cp++ == '-' )
  238.                         while( *cp )
  239.                             switch( *cp++ )
  240.                                 {
  241.                                 case    '2'    :    /* 2 columns */
  242.                                     prCols = 2;
  243.                                     break;
  244.                                 case    '3'    :    /* 3 columns */
  245.                                     prCols = 3;
  246.                                     break;
  247.                                 case    '4'    :    /* 4 columns Mega dpi */
  248.                                     prCols = 4;
  249.                                     break;
  250.                                 case    'l'    :    /* landscape */
  251.                                     portrait = FALSE;
  252.                                     break;
  253.                                 case    'n'    :    /* no headers */
  254.                                     prHeader = FALSE;
  255.                                     break;
  256.                                 case    's'    :    /* Do setup dialog */
  257.                                     prSetup = TRUE;
  258.                                     break;
  259.                                 case    'j'    :    /* do Job dialog */
  260.                                     prJob = TRUE;
  261.                                     break;
  262.                                 }
  263.                     }
  264.  
  265.                 if( prSetup )
  266.                     DoPageSetup();
  267.         
  268.                 for( i = 1; i < (**MyShell).Proc[ ProcID ].argc; i++ )
  269.                     {
  270.                     GetArgv( ShellWh, ProcID, i, argument );
  271.                     if( *argument != '-' )
  272.                         PrFiles( ShellWh, ProcID, argument );
  273.                     }
  274.  
  275.                 /* Tell the shell that we're done */
  276.                 SendOutToken(  ShellWh, ProcID, PROC_BREAK );
  277.                 
  278.                 /* Turn ourself off */
  279.                 (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  280.                 return( FALSE );
  281.                 }
  282.         }
  283. }
  284.